package com.example.jedis_pool.test;

import com.example.jedis_pool.jedis_config.Config;
import redis.clients.jedis.Jedis;

import java.util.List;
import java.util.Set;

public class testSet {

    public static void main(String[] args) {

        testSet.setKeyValue();
        testSet.getKeyValue();
        //关闭连接
        jedis.close();
    }
    //获取连接
    private static Jedis jedis= Config.JedisPool().getResource();

    //创建string0到string5
    public static void setKeyValue(){
        //更改数据库
        jedis.select(3);
        jedis.flushDB();

        Long i = jedis.sadd("set", "set-value-0", "set-value-1", "set-value-2", "set-value-3", "set-value-4");
        System.out.println(i);//返回value的个数

        jedis.sadd("set1","set1-value-0","set1-value-1","set1-value-2","set-value-3","set-value-4");

    }

    public static void getKeyValue() {

        Set all= jedis.smembers("set");//从集合中取出所有值，但是不删除
        System.out.println(all);

        Boolean b = jedis.sismember("set", "set1-value-0");//判断集合<key>是否为含有该<value>值，有1，没有0
        System.out.println(b);

        //从集合中随机弹出一个值
        System.out.println(jedis.spop("set"));

        System.out.println(jedis.scard("set"));

        jedis.smove("set","set1","set-value-0");

        Set<String> sin = jedis.sinter("set", "set1");
        System.out.println(sin);

        Set<String> sun = jedis.sunion("set", "set1");
        System.out.println(sun);

        Set<String> sdi = jedis.sdiff("set", "set1");
        System.out.println(sdi);



    }
}
